﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using devtm.Aop.Event;
using System.Reflection;
using System.Diagnostics;

namespace devtm.Aop.Behavior
{



    public enum BehaviorEnum
    {
        Unspecified,
        Ignore
    }


    /// <summary>
    /// Base form all interception attribute
    /// </summary>
    [AttributeUsage(
        AttributeTargets.Assembly | 
        AttributeTargets.Class | 
        AttributeTargets.Constructor | 
        AttributeTargets.Interface | 
        AttributeTargets.Method | 
        AttributeTargets.Property | 
        AttributeTargets.Parameter | 
        AttributeTargets.Event, 
      AllowMultiple = true, 
      Inherited = true)]
    public abstract class InterceptAttribute : Attribute
    {


        public InterceptAttribute()
        {

        }


        public BehaviorEnum Behevior { get; set; }


        [System.Diagnostics.DebuggerStepThrough]
        public static InterceptEventArgs Get(params object[] parameters)
        {

            var s = new StackTrace();
            StackFrame f = s.GetFrame(1);

            InterceptEventArgs args = new InterceptEventArgs(f, parameters) { FrameIndex = s.FrameCount };

            return args;

        }


        protected static void Error(InterceptEventArgs arg, Exception e)
        {
            if (ErrorEvents != null)
                ErrorEvents(e, arg);
        }


        public static event EventHandler<InterceptEventArgs> ErrorEvents;

    }


}
